package com.qf.service.impl;

import com.qf.entity.Student;
import com.qf.mapper.StudentMapper;
import com.qf.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lenovo
 * @version V1.0
 * @Date 2021/10/6 1:12
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> findAll() {
        return studentMapper.findAll();
    }

    @Override
    public List<Student> findAllByClassId(Integer id) {
        return studentMapper.findAllByClassId(id);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void add(Student student) {
        int insert = studentMapper.insert(student);
        if (insert != 1){
            System.out.println("添加失败");
            throw new RuntimeException("添加失败");
        }

    }
}
